<!--
**Thumb Image Viewer**
Create By ChenReal 2008-6-1
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<link href="browser.css" type="text/css" rel="stylesheet" />
	<script type="text/javascript" src="js/common.js"></script>	
	<script type="text/javascript">

var oListManager = new Object() ;

oListManager.Clear = function()
{
	document.body.innerHTML = '' ;
}

oListManager.GetFolderRowHtml = function( folderName, folderPath )
{
	// Build the link to view the folder.
	var sLink = '<a href="#" class="pic" onclick="OpenFolder(\'' + folderPath.replace( /'/g, '\\\'') + '\');return false;">' ;
	return '<li>' +			
				sLink +
				'<img alt="" src="images/Folder2.gif" border="0"></a>' +							
				folderName + 				
		'</li>' ;
}

oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )
{
	// Build the link to view the folder.
	var sLink = '<a href="#" class="pic" onclick="OpenFile(\'' + fileUrl.replace( /'/g, '\\\'') + '\');return false;" title="'+fileName + '(' + fileSize + ' KB)'+'">' ;

	// Get the file icon.
	var sIcon = oIcons.GetIcon( fileName ) ;    
	return '<li>' +			
			    sLink + 
			    "<img onload='funcResizeImg(this,100,100)' src='"+fileUrl.replace( /'/g, '\\\'') +"' style='display:none' /></a>"+				
				fileName + ' <br />(' + fileSize + ' KB)' +
		'</li>' ;
}

function OpenFolder( folderPath )
{
	// Load the resources list for this folder.
	window.parent.frames['frmFolders'].LoadFolders( folderPath ) ;
}

function OpenFile( fileUrl )
{
	window.top.opener.SetUrl( fileUrl ) ;
	window.top.close() ;
	window.top.opener.focus() ;
}

function LoadResources( resourceType, folderPath )
{
	oListManager.Clear() ;
	oConnector.ResourceType = resourceType ;
	oConnector.CurrentFolder = folderPath ;
	oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ;
}

function Refresh()
{
	LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ;
}

function GetFoldersAndFilesCallBack( fckXml )
{
	if ( oConnector.CheckError( fckXml ) != 0 )
		return ;

	// Get the current folder path.
	var oNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' ) ;
	var sCurrentFolderPath	= oNode.attributes.getNamedItem('path').value ;
	var sCurrentFolderUrl	= oNode.attributes.getNamedItem('url').value ;

//	var dTimer = new Date() ;

	var oHtml = new StringBuilder( '<ul class="Img">' ) ;

	// Add the Folders.	
	var oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' ) ;
	for ( var i = 0 ; i < oNodes.length ; i++ )
	{
		var sFolderName = oNodes[i].attributes.getNamedItem('name').value ;
		oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/" ) ) ;
	}

	// Add the Files.	
	var oNodes = fckXml.SelectNodes( 'Connector/Files/File' ) ;
	for ( var i = 0 ; i < oNodes.length ; i++ )
	{
		var oNode = oNodes[i] ;
		var sFileName = oNode.attributes.getNamedItem('name').value ;
		var sFileSize = oNode.attributes.getNamedItem('size').value ;

		// Get the optional "url" attribute. If not available, build the url.
		var oFileUrlAtt = oNodes[i].attributes.getNamedItem('url') ;
		var sFileUrl = oFileUrlAtt != null ? oFileUrlAtt.value : sCurrentFolderUrl + sFileName ;
		
		oHtml.Append( oListManager.GetFileRowHtml( sFileName, sFileUrl, sFileSize ) ) ;
	}

	oHtml.Append( '</ul><div style="clear:both"></div>' ) ;
	
	document.body.innerHTML = oHtml.ToString() ;

//	window.top.document.title = 'Finished processing in ' + ( ( ( new Date() ) - dTimer ) / 1000 ) + ' seconds' ;

}

//resize images By ChenReal 2007-9-5
function funcResizeImg(SourceImage,limitWidth,limitHeight)
{
    tempImage=new Image()
    tempImage.src=SourceImage.src
    SourceImage.style.display="";
    if(tempImage.width!=0&&tempImage.height!=0)
    {
        if(tempImage.width/tempImage.height>= limitWidth/limitHeight)
        { 
                if(tempImage.width>limitWidth)
                {
                    SourceImage.width=limitWidth; 
                    SourceImage.height=(tempImage.height*limitWidth)/tempImage.width; 
                }
                else
                { 
                    SourceImage.width=tempImage.width;
                    SourceImage.height=tempImage.height; 
                } 
        } 
        else
        { 
            if(tempImage.height>limitHeight)
            {
                SourceImage.height=limitHeight; 
                SourceImage.width=(tempImage.width*limitHeight)/tempImage.height; 
            }
            else
            { 
                SourceImage.width=tempImage.width;
                SourceImage.height=tempImage.height; 
            } 
        }
        SourceImage.style.marginLeft = (limitWidth - SourceImage.width) / 2;
        SourceImage.style.marginTop = (limitHeight - SourceImage.height) / 2;
    }
}


window.onload = function()
{
	window.top.IsLoadedResourcesList = true ;	
}
	</script>
</head>
<body class="FileArea" bottommargin="10" leftmargin="10" topmargin="10" rightmargin="10">
</body>
</html>
